package com.etc.delivery.service.user.impl;

import com.etc.delivery.dao.user.IUserDao;
import com.etc.delivery.entity.User;
import com.etc.delivery.service.user.IUserService;
import com.etc.delivery.utils.MD5Utils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("userServiceImpl01")
public class UserServiceImpl implements IUserService {

    @Resource
    private IUserDao iUserDao;

    @Override
    public boolean register(User user) {
        user.setPassword(MD5Utils.getPWD(user.getPassword()));
        boolean flag = iUserDao.register(user);
        return flag;
    }

    @Override
    public User userLogin(String phone, String password) {
        User user = iUserDao.userLogin(phone, MD5Utils.getPWD(password));
        return user;
    }

    @Override
    public User queryUserPhone(String phone) {
        User user = iUserDao.queryUserPhone(phone);
        return user;
    }

    @Override
    public List<User> queryUserPhone1(String phone) {

        return iUserDao.queryUserPhone1(phone);
    }

    @Override
    public boolean updateUser(User user) {
        return iUserDao.updateUser(user);
    }

    @Override
    public boolean deleteUser(int id) {
        return iUserDao.deleteUser(id);
    }

    @Override
    public boolean updateBalance2(double balance, String phone) {
        List<User> list = iUserDao.queryBalance(phone);
        double balance1 = list.get(0).getBalance();
        double balance2 = balance1 + balance;
        return iUserDao.updateBalance2(balance2, phone);
    }


}
